/*
 * $LastChangedRevision: 40 $
 */
package model.components;

import controller.Pool;
import controller.PoolItem;

public class Component extends Thread {
	private int componentId;
	private String label;
	private double state; // From 0 to 1 to represent the state.
	protected Pool eventPool = new Pool();
	private Pool actionPool = new Pool();

	public Component(String pLabel, double pState) {
		componentId = -1;
		label = pLabel;
		state = pState;
	}

	/**
	 * @return the id
	 */
	public int getComponentId() {
		return componentId;
	}

	/**
	 * @param pId
	 *            the id to set
	 */
	public void setComponentId(int pId) {
		componentId = pId;
	}

	/**
	 * @return the label
	 */
	public String getComponentLabel() {
		return label;
	}

	/**
	 * @param pLabel
	 *            the label to set
	 */
	public void setComponentLabel(String pLabel) {
		label = pLabel;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Component [id=" + componentId + ", label=" + label + "]";
	}

	public boolean insertToPool(String type, PoolItem pi) {
		if (type.compareTo("action") == 0) {
			return actionPool.insertPoolItem(pi.getItemId(), pi.getReferencedObjectId());
		} else if (type.compareTo("event") == 0) {
			return eventPool.insertPoolItem(pi.getItemId(), pi.getReferencedObjectId());
		}
		return false;
	}

	public double getComponentState() {
		return state;
	}

	public void setComponentState(double state) {
		this.state = state;
	}
}
